package com.nercl.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.nercl.dao.DeptDao;
import com.nercl.dao.impl.DeptDaoImpl;

/**
 * Servlet implementation class DeleteDeptServlet
 */
@WebServlet("/DeleteDeptServlet")
public class DeleteDeptServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public DeleteDeptServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doPost(request,response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		response.setCharacterEncoding("utf-8");//设置response编码方式
		request.setCharacterEncoding("utf-8");//设置request编码方式
		int depno = Integer.parseInt(request.getParameter("depno"));//获得路径中的参数
		System.out.println("---------------"+depno);
		DeptDao dao = new DeptDaoImpl();
		dao.delete(depno);//调用删除方法
		response.sendRedirect("IndexServlet");//页面重定向到查询全部部门信息的Servlet
	}

}
